<%@ page import="com.oceansoft.mobile.econsole.common.constant.Constant" %>
<%--
  Created by IntelliJ IDEA.
  User: zhuya
  Date: 2016/1/28
  Time: 16:45
  所有咨询
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>我的咨询</title>
    <link rel="stylesheet" href="<c:url value="/resource/wechat/css/frozen.css"></c:url>">
    <link rel="stylesheet" type="text/css" href="<c:url value="/resource/wechat/css/main.css"></c:url>"/>
    <style type="text/css">
        .sslk_more {
            width: 98%;
            float: left;
            margin-left: 1%;
            height: 35px;
            line-height: 35px;
            color: #6b6e75;
            text-align: center;
            /*background: rgb(109, 189, 99);*/
            border-radius: 3px;
            clear: both;
            margin-top: 15px;
            margin-bottom: 15px;
            font-family: "微软雅黑", "黑体", "宋体";
            font-size: 0.9em;
        }

        .sslk_more a {
            color: #fff;
            text-decoration: none;
        }
    </style>
</head>
<body ontouchstart class="bg_fff">
<section class="ui-container">
    <div class="mart20"></div>
<%--    <div class="search_wrap">
        <div class="search_main">
            <div class="search_main_rt">
                <input type="button" onclick="searchKeys();"/>
            </div>
            <div class="search_main_lf">
                <input type="text" placeholder="关键字搜索" id="keyword"/>
            </div>
        </div>
    </div>--%>
    <div class="ui-btn-wrap">
        <button class="ui-btn-lg ui-btn-primary" onclick="ask()">
            我要提问
        </button>
    </div>
    <div style="clear: both;"></div>
    <div id="all_zx_main">
    </div>
    <form method="post" id="mydForm">
        <input type="hidden" id="evaluationGrade" name="evaluationGrade">   <%--评价结果--%>
        <input type="hidden" id="evaluationContent" name="evaluationContent">  <%--评价内容--%>
        <input type="hidden" id="createUserName" name="createUserName" value="${member.aliasName}">  <%--评价姓名--%>
        <input type="hidden" id="createUserId" name="createUserId" value="${member.guid}">
        <input type="hidden" id="evaluaTionType" name="evaluaTionType" value="1">
        <input type="hidden" id="prjGuid" name="prjGuid">
    </form>
    <div class="sslk_more" style="cursor: pointer;" id="moreButton">加载更多</div>
</section>
<script src="<c:url value='/resource/js/jquery-2.0.min.js'/>"></script>
<script src="<c:url value="/resource/js/jquery.serializejson.min.js"/>"></script>
<script type="text/javascript">
    var page_index = 1;
    $(function () {
        search();
        $("#moreButton").click(function () {
            page_index++;
            search();
        });
    });

    //我要提问跳转
    function ask() {
        location.href = "<c:url value='/weixin/bszx/askQuestion?pt=${pt}'/>";
    }
    function searchKeys() {
        page_index = 1;
        $("#all_zx_main").empty();
        search();
    }

    function showAns(obj, answerTimeB, conetent) {
        if ($(obj).hasClass("hasClick")) {
            return;
        } else {
            $(obj).addClass("hasClick");
        }
        content = '<div class="wdzx_main" onclick="doClear(this)">'
                + '<div class="wdzx_main_ren ren2"><img src="<c:url value="/resource/wechat/images/wdzx_ren.png"></c:url>"/></div>'
                + '<div class="wdzx_main_gongg left">'
                + '<div class="img1"><img src="<c:url value="/resource/wechat/images/jiantou1.png"></c:url>"/></div>'
                + '<div class="main">'
                + '<div class="main_neir">'
                + '<p>' + conetent + '</p>'
                + '<p class="pa">'+answerTimeB+'</p> </div> </div> </div> </div>';

        $(obj).after(content);
        /*else {
            content = '<div class="wdzx_main" onclick="doClear(this)">'
                    + '<div class="wdzx_main_ren ren2"><img src="<c:url value="/resource/wechat/images/wdzx_ren.png"></c:url>"/></div>'
                    + '<div class="wdzx_main_gongg left">'
                    + '<div class="img1"><img src="<c:url value="/resource/wechat/images/jiantou1.png"></c:url>"/></div>'
                    + '<div class="main">'
                    + '<div class="main_neir">'
                    + '<p>当前咨询，没有回答。</p></div> </div> </div> </div>';

        }*/


    }

    function doClear(obj) {
        var pre = $(obj).prev();
        $(pre).removeClass("hasClick");
        $(obj).remove();
    }
    function search() {
        var userGuid = "${member.guid}";
        var url = "<c:url value='/api/matters/page/consults'/>";
        var keyword = $("#keyword").val();

        $.ajax(url, {
            type: "post",
            data: '{"keywords":"'+ $("#keyword").val() + '","numPerPage":"10","pageNum":' + page_index +',"userGuid":"'+ userGuid+'"}',
            contentType:"application/json",
            success: function (msg) {
                if (msg.succ) {
                    if (msg.data.list) {
                        addTolist(msg.data.list);
                        if (msg.data.hasNext) {
                            $("#moreButton").css("visibility", "visible");
                        }
                        else {
                            $("#moreButton").css("visibility", "hidden");
                        }
                    }
                } else {
                    $("#moreButton").css("visibility", "hidden");
                }
            },
            error: function (resp) {
                //  console.info(JSON.stringify(resp));
            }
        });
    }

    function addTolist(result) {
        var content = "";
        var text = "";
        for (var i = 0; i < result.length; i++) {
            var consultAnswer = result[i].consultAnswer;
            if(consultAnswer) {
                text = '<div class="wdzx_main" onclick="showAns(this, \'' + consultAnswer.answerTimeB+ '\', \'' + consultAnswer.conetent+ '\')">';
            }else {
                text = '<div class="wdzx_main">';
            }
            content += text
                    + '<div class="wdzx_main_ren ren1"><img src="<c:url value="/resource/wechat/images/wdzx_ren.png"></c:url>"/></div>'
                    + '<div class="wdzx_main_gongg right">'
                    + '<div><img src="<c:url value="/resource/wechat/images/jiantou.png"></c:url>"/></div>'
                    + '<div class="main">'
                    + '<div class="main_neir">'
                    + '<p>' + result[i].content + '</p>'
                    + '<p class="pa">' + result[i].cosTime + '<span class="lf0_orange">'
                    + fyReply(consultAnswer) + '</span></p></div></div></div></div></div>'
                    /*+ getMyd(result[i].guid, result[i].consultAnswer)*/;
        }
        $("#all_zx_main").append(content);
    }
    function fyReply(isReply) {
        if (!isReply) {
            return "未回复";
        } else {
            return "已回复";
        }
    }

    function getMyd(guid, isReply, myd) {
        var content = '';
        if ("1" == isReply && '待评价' == myd) {
            content = '<div class="wdzx_myd" id="prj_' + guid + '">请评价 <input type="radio" name="pj"  value="0" onclick="doPj(this,\'' + guid + '\');"/>满意 <input type="radio" name="pj"  value="1" onclick="doPj(this,\'' + guid + '\');"/>基本满意<input type="radio" name="pj" value="2" onclick="doPj(this,\'' + guid + '\');"/>不满意</div>';
        }
        return content;
    }

    function getConetnt(content) {
        if (content) {
            return content;
        } else {
            return '';
        }
    }
    function doPj(obj, prjGuid) {
        if(!confirm("确定对此回复进行评价")){
            return false;
        }
        var mydC = '满意';
        var evaluationGrade = $(obj).val();
        if ("1" == evaluationGrade) {
            mydC = "基本满意";
        } else if ("2" == evaluationGrade) {
            mydC = "不满意";
        }
        $("#evaluationGrade").val(evaluationGrade);
        $("#evaluationContent").val(mydC);
        $("#prjGuid").val(prjGuid);
        var form = $("#mydForm").serializeJSON();
        $.ajax({
            url:"<c:url value="/api/matters/product/myd"></c:url>",
            data:JSON.stringify(form),
            type:'post',
            contentType:"application/json",
            success:function(resp){
                if (resp["succ"] ) {
                    $("#myd_" + prjGuid).text(mydC);
                    $("#prj_" + prjGuid).remove();
                    alert("评价成功");
                } else {
                   alert("评价失败，请重新评价")
                }
            },
            error:function(resp){
                alert("提交失败,请重新操作");
            }
        });
    }
</script>
</body>
</html>